import java.util.ArrayList;
public class Solution {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
        ArrayList<Integer> list = new ArrayList<>();
        int q = 0, h = 1, mq = q, mh = h, curSum = q;
        while (h <= array.length - 1 && q <= h) {
            if (curSum > sum) {
                curSum -= array[q];
                q++;
            } else if (curSum < sum) {
                h++;
                curSum += array[h];
            } else if (curSum == sum) {
                list.add(q);
                list.add(h);
                return list;
            }

        }
        return new ArrayList<>();
    }
}